<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: TZZ
  Date: 2020/5/15
  Time: 17:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%@include file="/bootstrap.jsp" %>
    <style type="text/css">
        .cz button {
            margin: 10px 20px;
        }

        .sub {
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div class="cz bg-info">
    <button type="botton" class="btn btn-primary" data-toggle="modal" data-target="#addModal">添加类型</button>
</div>
<%--类型列表--%>
<table class="table-hover table-striped table-bordered table">
    <thead class="table-dark">
    <tr>
        <td>类型编号</td>
        <td>类型名称</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${typeList}" var="type">
        <tr>
            <td>${type.t_id}</td>
            <td>${type.t_name}</td>
            <td>
                <a type="button" class="btn btn-danger" onclick="deleteType('${type.t_id}')" style="color: white;text-decoration: none">删除</a>
                </a>
                <a class="btn btn-info" type="button" data-toggle="modal" data-target="#updateModal" onclick="updateType('${type.t_id}','${type.t_name}')"
                       style="color: white;text-decoration: none">修改
                </a>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>

<script type="text/javascript">
    function updateType(t_id,t_name) {
        document.getElementById("updateId").value = t_id;
        document.getElementById("updateName").value = t_name;
    }
    function deleteType(t_id) {
        var con=confirm("是否删除?");
        if(con){
            location.href = "${pageContext.request.contextPath}/TypeDeleteServlet.filter?method=typeDelete&t_id="+t_id;
        }
    }
</script>
<!-- 添加模态框 -->
<div class="modal fade" id="addModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- 模态框头部 -->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <!-- 模态框主体 -->
            <div class="modal-body">
                <form class="bs-example bs-example-form" role="form"
                      action="${pageContext.request.contextPath}/TypeAddServlet.filter?method=typeAdd">
                    <%--类型名称--%>
                        <div class="form-group">
                            <label>类型名称:</label>
                        <input type="text" class="form-control" placeholder="类型名称" name="t_name">
                    </div>
                    <br>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                        </button>
                        <button type="submit" class="btn btn-primary">
                            提交
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- 修改模态框（Modal） -->
<div class="modal fade" id="updateModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div style="padding: 10px;">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                </div>
                <form class="bs-example bs-example-form" role="form"
                      action="${pageContext.request.contextPath}/TypeUpdateServlet.filter?method=typeUpdate">
                    <div class="form-group">
                        <label for="updateId">类型编号:</label>
                        <input type="text" class="form-control" placeholder="类型编号" id="updateId" name="t_id" value="" >
                    </div>
                    <%--类型名称--%>
                        <div class="form-group">
                            <label for="updateName">类型名称:</label>
                            <input type="text" class="form-control" placeholder="类型名称" id="updateName" name="t_name" value="">
                        </div>
                    <br>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">
                            关闭
                        </button>
                        <button type="submit" class="btn btn-primary">
                            提交
                        </button>
                    </div>
                </form>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

</body>
</html>
